package ar.com.spsolutions.splibrary.book;

import java.util.Set;

import org.joda.time.DateTime;

import ar.com.spsolutions.splibrary.notifiers.INotifier;
import ar.com.spsolutions.splibrary.user.User;
import ar.com.spsolutions.splibrary.user.UserBuilder;

public class ReserveBuilder {

	private transient Reserve toBuild;

	private transient INotifier notifier;

	public static Reserve createInstanceForTest() {
		return new ReserveBuilder(null)//
				.withBook(BookBuilder.createInstanceForTest())//
				.withCustomer(UserBuilder.createInstanceForTest())//
				.build();
	}

	public ReserveBuilder(final INotifier aNotifier) {
		this.toBuild = new Reserve(aNotifier);
		this.notifier = aNotifier;
	}

	public INotifier getNotifier() {
		return this.notifier;
	}

	public ReserveBuilder withCustomer(final User value) {
		this.getToBuild().setCustomer(value);
		return this;
	}

	public ReserveBuilder withBook(final Book value) {
		this.getToBuild().setBook(value);
		return this;
	}

	public ReserveBuilder withObservers(final Set<User> value) {
		this.getToBuild().setObservers(value);
		return this;
	}

	public ReserveBuilder withDue(final DateTime value) {
		this.getToBuild().setDue(value);
		return this;
	}

	public Reserve build() {
		final Reserve temp = this.getToBuild();
		this.toBuild = new Reserve(this.getNotifier());
		return temp;
	}

	private Reserve getToBuild() {
		return this.toBuild;
	}
}
